﻿using EIP.Authorize.Logic.Models;
using EIP.Common.Repository;
using System;
using System.Threading.Tasks;

namespace EIP.Authorize.Logic.Repository.Impl
{
    public class AccountRepository : IAccountRepository
    {
        /// <summary>
        /// 根据登录代码和密码查询用户信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Task<LoginOutput> Login(LoginInput input)
        {
            string sql = "SELECT UserId,OrganizationId,OrganizationName,Code,Name ,IsFreeze,IsAdmin  FROM System_UserInfo where Code=@code and Password=@password";
            return new SqlMapperUtil().SqlWithParamsSingle<LoginOutput>(sql, new
            {
                code = input.Code,
                password = input.Password
            });
        }

        /// <summary>
        /// 更新最后时间
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public Task<bool> UpdateTime(Guid userId)
        {
            string sql = "UPDATE System_UserInfo SET LastVisitTime=@time WHERE UserId=@userId ";
            return new SqlMapperUtil().InsertUpdateOrDeleteSqlBool<bool>(sql, new
            {
                time = DateTime.Now,
                userId
            });
        }
    }
}